package cc.rengu.redp.job.domain;

import cc.rengu.redp.common.annotation.IsCron;
import cc.rengu.redp.common.converter.CustomConverter;
import cc.rengu.redp.common.converter.ExcelCustomConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

@Data
@ExcelIgnoreUnannotated
@TableName("t_job")
public class Job implements Serializable {

    private static final long serialVersionUID = 400066840871805700L;

    /**
     * 任务调度参数 key
     */
    public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";

    public enum ScheduleStatus {
        /**
         * 正常
         */
        NORMAL("0"),
        /**
         * 暂停
         */
        PAUSE("1");

        private String value;

        ScheduleStatus(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }

    @TableId(value = "JOB_ID")
    private Long jobId;

    @NotBlank(message = "{required}")
    @Size(max = 50, message = "{noMoreThan}")
    @ExcelProperty(value = "Bean名称")
    private String beanName;

    @NotBlank(message = "{required}")
    @Size(max = 50, message = "{noMoreThan}")
    @ExcelProperty(value = "方法名称")
    private String methodName;

    @Size(max = 50, message = "{noMoreThan}")
    @ExcelProperty(value = "方法参数")
    private String params;

    @NotBlank(message = "{required}")
    @IsCron(message = "{invalid}")
    @ExcelProperty(value = "Cron表达式")
    private String cronExpression;

    @ExcelProperty(value = "状态", converter = CustomConverter.class)
    @ExcelCustomConvert(value = {"0", "1"}, label = {"正常", "暂停"})
    private String status;

    @Size(max = 100, message = "{noMoreThan}")
    @ExcelProperty(value = "备注")
    private String remark;

    @ExcelProperty(value = "创建时间")
    private Date createTime;

    @TableField(exist = false)
    private String createTimeFrom;

    @TableField(exist = false)
    private String createTimeTo;

}
